#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "Meet"
# Date: 2019-10-15


from bs4 import BeautifulSoup
import requests
data = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) '
                  'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36'
}

for i in range(5):
    print('正在爬取第%s页图片' % (i + 1))
    ret = requests.get('https://bing.ioliu.cn/?p=%s' % (i + 1))
    bs = BeautifulSoup(ret.text, 'html.parser')
    img_list = bs.find_all(name='img')

    for img in img_list:
        img_url = img.get('src')
        print(img_url)
        img_ret = requests.get(img_url,headers=data)
        with open(img_url.rsplit('/', maxsplit=1)[-1], 'wb')as f:
            f.write(img_ret.content)


